<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no"/>
    <meta charset="utf-8">
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
    <title>Higher Order Components</title>
</head>
<body>
<div id="react-container"></div>
  <script type="text/babel">

    const { Component } = React
    const { render } = ReactDOM

    class PeopleList extends Component {

      constructor(props) {
          super(props)
          this.state = {
              data: [],
              loaded: false,
              loading: false
          }
      }

      componentWillMount() {
        this.setState({loading:true})
        fetch('https://randomuser.me/api/?results=10')
            .then(response => response.json())
            .then(obj => obj.results)
            .then(data => this.setState({
                  loaded: true,
                  loading: false,
                  data
              }))
      }

      render() {
          const { data, loading, loaded } = this.state
          return (loading) ?
              <div>Loading...</div> :
              <ol className="people-list">
                  {data.map((person, i) => {
                      const {first, last} = person.name
                      return <li key={i}>{first} {last}</li>
                  })}
              </ol>
      }
    }
    render(
      <PeopleList />,
      document.getElementById('react-container')
    )

  </script>
</body>
</html>
